function addRole() {

    var rolename = $("#rolename").val();
    var roleDescribe = $("#roleDescribe").val();

    function showErrorMess(ms) {
        $("#hint").html(ms);
    }

    if (rolename == null || rolename == "") {
        showErrorMess("名称不能为空！");
        return false;
    }

    if (roleDescribe == null || roleDescribe == "") {
        showErrorMess("描述不能为空！");
        return false;
    }

    return true;
}

function role_delete() {
    var obj = document.getElementsByName("box");

    var flag = false;

    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            flag = true;
            break;
        }
    }

    if (!flag) {
        alert("请选择角色！");
    }

    var check_val = [];
    for (var k in obj) {
        if (obj[k].checked) {
            check_val.push(obj[k].value);
        }
    }
    if (check_val.length > 0) {
        if (confirm("您确定要删除吗？")) {
            if (confirm("不要急躁，再想一想！")) {
                $.ajax({
                    type: "GET",
                    traditional: true,//阻止深度序列化
                    url: "/role/AjaxDelete",
                    dataType: 'json',
                    data: {"ids": check_val, "status": 0},
                    async: false,
                    contentType: "application/json; charset=utf-8",
                    success: function (feedback) {
                        if (feedback == true) {
                            location.reload(true);
                        }
                    }
                });
            }
        }
    }
}

function role_update() {

    var obj = document.getElementsByName("box");

    var flag = false;

    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            flag = true;
            break;
        }
    }

    $("#updateRole").attr('data-toggle', 'modal');
    $("#updateRole").attr('data-target', '#update');

    if (!flag) {
        alert("请选择你要编辑的角色！");
        $("#updateRole").removeAttr("data-toggle");
        $("#updateRole").removeAttr("data-target");
    }

    var check_val = [];
    for (var k in obj) {
        if (obj[k].checked) {
            check_val.push(obj[k].value);
        }
    }

    if (check_val.length > 1) {
        alert("暂时只支持单个修改！");
        $("#updateRole").removeAttr("data-toggle");
        $("#updateRole").removeAttr("data-target");
    }

    if (check_val.length == 1) {
        $.ajax({
            type: "GET",
            url: "/role/AjaxRoleById",
            dataType: 'json',
            data: {"id": check_val.toString()},
            async: false,
            success: function (data) {
                $("#RoleId").val(data.roleById.id);
                $("#rolename2").val(data.roleById.rolename);
                $("#roleDescribe2").val(data.roleById.roleDescribe);
            }
        });

    }
}

function updateRole() {

    var rolename2 = $("#rolename2").val();
    var roleDescribe2 = $("#roleDescribe2").val();

    function showErrorMess(ms) {
        $("#updateHint").html(ms);
    }

    if (rolename2 == null || rolename2 == "") {
        showErrorMess("名称不能为空！");
        return false;
    }

    if (roleDescribe2 == null || roleDescribe2 == "") {
        showErrorMess("描述不能为空！");
        return false;
    }

    return true;
}